import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import moment from 'moment';
import { rules } from '@pkg/utils';
import { payWayList } from './api';
import { vipcardList } from '@apps/ant-bus/src/views/business/goods/vipcard/data/api';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { xunLianPayParamList } from '@apps/ant-bus/src/views/business/payset/xunlianPayparam/api';
import { yinLianPayParamList } from '@apps/ant-bus/src/views/business/payset/yinlianPayparam/api';
import { companyList } from '@apps/ant-bus/src/views/business/companyManage/company/data/api';
import { RenderType } from '@pkg/setting';

export const columns: BasicColumn[] = [
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '会员账号',
    dataIndex: 'mainAccount',
    width: 120,
  },
  {
    title: '会员姓名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '紧急手机号',
    dataIndex: 'telePhone',
    width: 120,
  },
  {
    title: '会员卡号',
    dataIndex: 'vipCardNo',
    width: 180,
  },
  {
    title: '证件类型',
    dataIndex: 'identityType',
    width: 120,
    dictData: [
      { label: '身份证', value: 1 },
      { label: '护照', value: 2 },
      { label: '港澳通行证', value: 3 },
      { label: '台胞证', value: 4 },
      { label: '其他', value: 5 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '证件号码',
    dataIndex: 'identityNo',
    width: 180,
  },
  {
    title: '卡种名称',
    dataIndex: 'goodsName',
    width: 150,
  },
  {
    title: '贵宾厅服务有效期',
    dataIndex: 'viproomDate',
    width: 140,
  },
  {
    title: '是否开票',
    dataIndex: 'applyInvoiceState',
    width: 120,
    dictData: [
      { label: '未开票', value: 0 },
      { label: '已开票', value: 1, color: '#00ee28' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '退款类型',
    dataIndex: 'refundSourceType',
    width: 120,
    dictData: [
      { label: '现办现退', value: 1, color: '#ee0303' },
      { label: '普通退卡', value: 2, color: '#032aee' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '开卡日期',
    dataIndex: 'buyDate',
    width: 120,
  },
  {
    title: '支付金额',
    dataIndex: 'payAmount',
    width: 120,
  },
  {
    title: '销售姓名',
    dataIndex: 'employeeName',
    width: 120,
  },
  {
    title: '合卡销售',
    dataIndex: 'heKaRemark',
    width: 120,
  },
  {
    title: '退卡时间',
    dataIndex: 'refundDate',
    width: 150,
  },
  {
    title: '开卡地',
    dataIndex: 'airportName',
    width: 120,
  },
  {
    title: '来源',
    dataIndex: 'sourceType',
    width: 120,
    dictData: [
      { label: '扫码注册', value: 1 },
      { label: '商城购买', value: 2 },
      { label: '销售新增', value: 3 },
      { label: '后台新增', value: 4 },
      { label: '后台导入', value: 5 },
      { label: '礼品卡接收', value: 6 },
      { label: '后台批量生成', value: 7 },
      { label: '销售赠送', value: 8 },
      { label: '代理商下单', value: 9 },
      { label: '企业下单', value: 10 },
      { label: '后台券码生成', value: 11 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '下单企业',
    dataIndex: 'companyName',
    width: 200,
  },
  {
    title: '收款方式',
    dataIndex: 'paywayName',
    width: 180,
  },
  {
    title: '微信支付Id',
    dataIndex: 'payInfoId',
    width: 170,
  },
  {
    title: '升降级卡种价格',
    dataIndex: 'upgradePayAmount',
    width: 120,
  },
  {
    title: '卡状态',
    dataIndex: 'vipCardState',
    width: 120,
    dictData: [
      { label: '待激活', value: 0 },
      { label: '正常', value: 1 },
      { label: '已过期', value: 2 },
      { label: '未开通', value: 3 },
      { label: '未通过', value: 4 },
      { label: '冻结', value: 5 },
      { label: '退卡中', value: 6 },
      { label: '已退卡', value: 7 },
      { label: '已转卡', value: 8 },
      { label: '已转赠', value: 9 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '贵宾厅服务状态',
    dataIndex: 'vipServerIsExpre',
    width: 140,
    dictData: [
      { label: '已过期', value: true },
      { label: '未过期', value: false },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 180,
  },
  {
    title: '标签',
    dataIndex: 'newestTagRemark',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mainAccount',
    label: '会员账号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'vipCardNo',
    label: '卡号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'employeeName',
    label: '销售',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'payType',
    label: '收款方式',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: ({ formActionType, formModel }) => {
      return {
        options: [
          { label: '全部', value: '' },
          { label: '讯联微信', value: 'PAY_WX' },
          { label: '银联微信', value: 'PAY_WX_YINLIAN' },
          { label: '线下支付', value: 'PAY_UNDERLINE' },
          { label: '扫码支付', value: 'PAY_QRCODE' },
        ],
        onChange: payType => {
          const { updateSchema } = formActionType;
          //所属部门修改后更新负责部门下拉框数据
          let componentProps = {};
          if (payType == 'PAY_WX' || payType == 'PAY_QRCODE') {
            componentProps = {
              api: xunLianPayParamList,
              labelField: 'paramName',
              valueField: 'xunlianPayparamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_WX_YINLIAN') {
            componentProps = {
              api: yinLianPayParamList,
              labelField: 'yinlianPayName',
              valueField: 'yinlianpayparamId',
              immediate: true,
              showSearch: true,
            };
          }
          if (payType == 'PAY_UNDERLINE') {
            componentProps = {
              api: payWayList,
              labelField: 'paywayName',
              valueField: 'paywayId',
              immediate: true,
              showSearch: true,
            };
          }
          updateSchema([
            {
              field: 'targetPayParamId',
              componentProps: componentProps,
            },
          ]);
          formModel.targetPayParamId = null;
        },
      };
    },
  },
  {
    field: 'targetPayParamId',
    label: '支付通道',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '请先选择收款方式',
    },
  },
  {
    field: 'payInfoId',
    label: '支付Id',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'goodsId',
    label: '卡种',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'airportId',
    label: '开卡地',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      params: { handlerName: 'busAirportRoleListHandler' },
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'vipCardState',
    label: '状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '待激活', value: 0 },
        { label: '正常', value: 1 },
        { label: '已过期', value: 2 },
        { label: '未开通', value: 3 },
        { label: '未通过', value: 4 },
        { label: '冻结', value: 5 },
        { label: '退卡中', value: 6 },
        { label: '已退卡', value: 7 },
        { label: '已转卡', value: 8 },
        { label: '已转赠', value: 9 },
      ],
    },
  },
  {
    field: 'sourceType',
    label: '来源',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '扫码注册', value: 1 },
        { label: '商城购买', value: 2 },
        { label: '销售新增', value: 3 },
        { label: '后台新增', value: 4 },
        { label: '后台导入', value: 5 },
        { label: '礼品卡接收', value: 6 },
        { label: '后台批量生成', value: 7 },
        { label: '销售赠送', value: 8 },
        { label: '代理商下单', value: 9 },
        { label: '企业下单', value: 10 },
        { label: '后台券码生成', value: 11 },
      ],
    },
  },
  {
    field: 'applyInvoiceState',
    label: '是否开票',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '未开票', value: 0 },
        { label: '已开票', value: 1 },
      ],
    },
  },
  {
    label: '合作企业',
    field: 'companyId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: companyList,
      labelField: 'companyName',
      valueField: 'companyId',
    },
  },
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const delayFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    colProps: { span: 24 },
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'expireDate',
    label: '过期日期',
    component: 'Input',
    colProps: { span: 24 },
    required: false,
    dynamicDisabled: true,
  },
  {
    label: '延期至',
    field: 'newExpireDate',
    required: true,
    component: 'DatePicker',
    colProps: { span: 24 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const upgradeFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'oldGoodsId',
    label: '旧卡种',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '所属机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange: () => {
          formModel.employeeId = null;
        },
      };
    },
  },
  {
    field: 'goodsId',
    label: '选择卡种',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: vipcardList,
        params: {
          handlerName: 'busVipCardListHandler',
          isTiyan: 0,
          oldGoodsId: formModel.oldGoodsId,
        },
        labelField: 'goodsName',
        valueField: 'goodsId',
        immediate: true,
        showSearch: true,
      };
    },
  },
];

export const nowBackCardFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'userName',
    label: '会员姓名',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'refundReason',
    label: '退卡原因',
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'remark',
    helpMessage: '请把会员退卡相关信息在此备注说明',
    label: '退卡备注',
    component: 'InputTextArea',
    required: true,
  },
];

export const editEmployeeFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'airportId',
    label: '所属机场',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: airportList,
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  }
];

export const editPrivateDataFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'lastName',
    label: '英文姓',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'firstName',
    label: '英文名',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    required: true,
  },
  {
    field: 'identityType',
    label: '证件类型',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '身份证', value: 1 },
          { label: '护照', value: 2 },
          { label: '港澳通行证', value: 3 },
          { label: '台胞证', value: 4 },
          { label: '其他', value: 5 },
        ],
        onChange: identityType => {
          console.info('identityType', identityType);
          if (identityType == 1) {
            formModel.lastName = null;
            formModel.firstName = null;
            formModel.nationality = null;
            formModel.sex = null;
            formModel.birthDate = null;
            formModel.issueAt = null;
            formModel.expiryDate = null;
          }
        },
      };
    },
  },
  {
    field: 'identityNo',
    label: '证件号',
    component: 'Input',
    required: false,
  },
  {
    field: 'telePhone',
    label: '应急电话',
    component: 'Input',
    required: false,
  },
  {
    field: 'nationality',
    label: '国籍',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'sex',
    label: '性别',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '女', value: 1 },
        { label: '男', value: 2 },
      ],
    },
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'birthDate',
    label: '出生日期',
    component: 'DatePicker',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'issueAt',
    label: '证件签发地',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
  {
    field: 'expiryDate',
    label: '证件有效期',
    component: 'DatePicker',
    required: true,
    ifShow: ({ model }) => {
      return model.identityType != 1;
    },
  },
];

export const editYaokePrivateDataFormSchema: FormSchema[] = [
  {
    field: 'userGoodsId',
    label: '会员卡Id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'vipCardNo',
    label: '会员卡号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'mobile',
    label: '会员手机号',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyName',
    label: '公司名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyAddress',
    label: '公司地址',
    component: 'Input',
    required: false,
  },
  {
    field: 'telePhone',
    label: '应急电话',
    component: 'Input',
    required: false,
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    required: false,
  },
];

export const addCheckFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '使用类型',
    field: 'checkType',
    component: 'Input',
    show: false,
    defaultValue: 1,
    required: true,
  },
  {
    label: '操作类型',
    field: 'optType',
    component: 'Input',
    show: false,
    defaultValue: 1,
    required: true,
  },
  {
    label: '会员卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '使用次数',
    field: 'useNum',
    component: 'InputNumber',
    defaultValue: 1,
    dynamicRules: () => rules.digits(true),
  },
  {
    label: '补录机场',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange: airportId => {
          formModel.employeeId = null;
          formModel.employeeServerId = null;
        },
      };
    },
  },
  {
    label: '使用时间',
    field: 'useDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
      disabledDate: current => {
        return current && current >= moment().add(0, 'day');
      },
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];

export const remarkFormSchema: FormSchema[] = [
  {
    label: '用户物品Id',
    field: 'userGoodsId',
    component: 'Input',
    show: false,
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];
